import { defineConfig } from "@umijs/max";
import tailwindcss from "tailwindcss";
import runtimeConfig from "../runtime-config/index";
import routes from "./routes";
const isProduction = process.env.UMI_ENV === "production";
const base = runtimeConfig.routeBase;
const publicPath = runtimeConfig.publicPath;

export default defineConfig({
  title: "使用基于umi开发",
  base: isProduction ? base : undefined,
  locale: {
    default: "zh-CN",
    antd: true,
    baseNavigator: true,
  },
  conventionRoutes: {
    exclude: [
      /\/shared?\//,
      /\/modules?\//,
      /\/components?\//,
      /\/hooks?\//,
      /.ts$/,
    ],
  },
  define: {
    "process.env.PROJECT_ENV": process.env.PROJECT_ENV,
    "process.env.UMI_ENV": process.env.UMI_ENV,
  },
  favicons: ["https://ant-design.gitee.io/favicon.ico"],
  access: false,
  model: {},
  initialState: {},
  request: false,
  layout: {
    title: "sailfish-umi-pro",
  },
  routes,
  extraPostCSSPlugins: [tailwindcss()],
  npmClient: "pnpm",
  proxy: {
    "/fe": {
      target: runtimeConfig.apiBaseUrl,
      changeOrigin: true,
      pathRewrite: {
        "^/fe": "",
      },
    },
  },
  outputPath: "./build",
  publicPath: isProduction ? publicPath : "/",
  hash: true,
  jsMinifierOptions: {
    drop: ["console", "debugger"],
  },
  headScripts: [
    {
      src: "//jsfile.guanmai.cn/build/libs/gm-i18n/2.11.0/gm-i18n.js",
      type: "text/javascript",
      "data-project": "sailfish-umi-pro",
    },
  ],
  chainWebpack(config) {
    config.set("externals", {
      "gm-i18n": "gmI18n",
    });
    return config;
  },
});

// // webpack 配置
// module.exports = function (config) {
//   config.externals = Object.assign({}, config.externals, {
//     'gm-i18n': 'gmI18n',
//   })
//   config.devServer = Object.assign({}, config.devServer, {
//     open: true,
//     host: '0.0.0.0',
//   })

//   return config
// }
